<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>highlight onclick - 4.6</title>

  <link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
  <script src="https://js.arcgis.com/4.6/"></script>

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <script>
    require([
        "esri/Map",
        "esri/views/SceneView",

        "esri/layers/FeatureLayer",
		"esri/Graphic",

        "dojo/domReady!"
      ],
      function(
        Map, SceneView,
        FeatureLayer,Graphic
      ) {

        var map = new Map({
          basemap: "osm"
        });

        var view = new SceneView({
          container: "viewDiv",
          map: map,

          extent: { // autocasts as new Extent()
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100
          }
        });

        var popupTemplate = { // autocasts as new PopupTemplate()
          title: "Tree_ID:{Tree_ID}",
		  content: "obj: {FID} , x:{Longitude},y: {Latitude}"
        };
        /********************
         * Add feature layer
         ********************/

        // Carbon storage of trees in Warren Wilson College.
        var featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
          //popupTemplate: popupTemplate
        });
		var highlight;
		view.on("click",function(event){
			if(highlight){
				highlight.remove();
			}
			view.hitTest(event).then(function(response){
				if(response.results[0]){
					var graphic = response.results[0].graphic;
					view.whenLayerView(graphic.layer).then(function(lyrView){
						highlight = lyrView.highlight(graphic);
					})
				}
			})
		});

        map.add(featureLayer);

      });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>